package com.hzcx.app.simplechat.ui.publicui;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.ui.chat.ChatGroupSettingActivity;
import com.hzcx.app.simplechat.ui.group.LiveData.GroupInfoBeanLiveData;
import com.hzcx.app.simplechat.ui.group.bean.GroupInfoBean;
import com.hzcx.app.simplechat.util.UserInfoUtil;
import com.hzcx.app.simplechat.util.glide.GlideUtils;

import butterknife.OnClick;

public class GroupQrCodeActivity extends QrCodeActivity {

//    public static String GroupInfoBeanKey = "QrCodeActivity_GroupInfoBean";
    public static String GroupInfoBeanKeyGroupID = "QrCodeActivity_GroupInfoBeanKeyGroupID";
    GroupInfoBean groupInfoBean;
    private String groupID;

    @Override
    public int getLayout() {
        return R.layout.activity_group_qrcode;
    }


    @Override
    public void initView() {
        tvTitle.setText("群二维码");
        ivTitleRight.setImageResource(R.mipmap.ic_icon_title_more);
        ivTitleRight.setVisibility(View.GONE);

//        groupInfoBean = (GroupInfoBean)getIntent().getExtras().getSerializable(GroupQrCodeActivity.GroupInfoBeanKey);
        groupID = getIntent().getStringExtra(GroupInfoBeanKeyGroupID);
        groupInfoBean = GroupInfoBeanLiveData.getGroupInfoBean(groupID);

        tvCardName.setText(getResources().getString(R.string.app_name) + "名片");
        tvTips.setText("扫描二维码,加入群聊");
    }

    @Override
    public void initData() {

//        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_icon_login_qq);
//        ivQrcode.setImageBitmap(QRCodeUtil.createQRCodeWithLogo("聊天软件", bitmap));

        GlideUtils.loadImgAsCircle(this, groupInfoBean.getGroup_image(), ivHead);
        tvNickName.setText(groupInfoBean.getGroup_name());
        tvUserId.setText("群号: " + groupInfoBean.getCustom_number());
        GlideUtils.loadImg(this, groupInfoBean.getGroup_qrcode(), ivQrcode);
    }

    @OnClick({R.id.tv_save, R.id.iv_title_right, R.id.tv_share})
    public void viewOnClick(View view) {
        switch (view.getId()) {
            case R.id.tv_save: // 保存图片
                super.registerPermission();
                break;

            case R.id.iv_title_right: // 更多
                super.showMoreDialog();
                break;

            case R.id.tv_share: // 分享
                startActivity(new Intent(this, ShareActivity.class)
                        .putExtra(ShareActivity.INTENT_USER_ID, groupInfoBean.getCustom_number()));
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + view.getId());
        }
    }
}